// 引入mock.js
let Mock = require('mockjs')
let Random = Mock.Random

function userList () {
   const user = Mock.mock({
      'userdata|300-400': [{
        'id|+1': 0,
        'useable|1-2': true,
        'sex|1': ['man', 'female'],
        'birthday': '@date("yyyy-MM-dd")',
        'useremail|+1': Random.email(),
        'group': 'user',
        'username': /[a-z][a-z][a-z][0-9][0-9][0-9]/,
        'password': /[a-z][a-z]\d{5}/,
        'avatarimg|+1': Random.image('120x120', '#409EFF', 'Avatar'),
        'comments|3-20': [{
          'commentid|+1': 0,
          'status|1-2': true,
          'commentshow': function () {
            let name = Random.csentence(4, 10)
            return name
          },
          'showrank|0-4.1': 1,
          'date': '@date("yyyy-MM-dd hh:mm:ss")',
          'content': function () {
            let text = Random.cparagraph(1, 3)
            return text
          },
          'imgnum|1-9': 1,
          'commentimg': function () {
            let arr = []
            for (let i = 0; i <= this.imgnum; i++) {
              let img = Random.image()
              arr.push(img)
            }
            return arr
          }
        }]
      }]
    })
   return user
 }
 
 // 以api路径为值，将userList函数暴露出去
 exports.user = userList
 